package cn.iocoder.yudao.module.movie.controller.app.convert;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.movie.api.domain.*;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppCinemaVO;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppCityRespVO;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppMovieCinemaVO;
import cn.iocoder.yudao.module.movie.controller.app.vo.AppMoviesRespVO;
import de.danielbechler.util.Collections;
import lombok.experimental.UtilityClass;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>  </p>
 */
@UtilityClass
public class MovieRespVOConvert {
    public static AppMoviesRespVO convert(MovieListDO movieListDO) {
        AppMoviesRespVO appMoviesRespVO = new AppMoviesRespVO();
        if (Collections.isEmpty(movieListDO.getMovies())) {
            appMoviesRespVO.setMovies(new ArrayList<>());
        }else {
            List<AppMoviesRespVO.MovieVO> movieVOList = movieListDO.getMovies().stream().map(MovieRespVOConvert::convert).collect(Collectors.toList());
            appMoviesRespVO.setMovies(movieVOList);
        }
        appMoviesRespVO.setCount(movieListDO.getCount());
        return appMoviesRespVO;
    }
    public static AppMoviesRespVO.MovieVO convert(MovieDO movieDO) {
        AppMoviesRespVO.MovieVO movieVO = BeanUtils.toBean(movieDO, AppMoviesRespVO.MovieVO.class);
        return movieVO;
    }
    /**
     * 城市信息
     * @param cityDO 城市信息
     * @return 城市信息
     */
    public static AppCityRespVO convert(CityDO cityDO) {
        return BeanUtils.toBean(cityDO, AppCityRespVO.class);
    }
    public static AppMovieCinemaVO convert(MovieCinemasDO movieCinemasDO) {
        AppMovieCinemaVO appMovieCinemaVO = BeanUtils.toBean(movieCinemasDO, AppMovieCinemaVO.class);
        if (movieCinemasDO.getCinemas() != null) {
            List<AppCinemaVO> cinemaVOList = movieCinemasDO.getCinemas().stream().map(MovieRespVOConvert::convert).collect(Collectors.toList());
            appMovieCinemaVO.setCinemas(cinemaVOList);
        }
        return appMovieCinemaVO;
    }
    public static AppCinemaVO convert(CinemaDO cinemaDO) {
        return BeanUtils.toBean(cinemaDO, AppCinemaVO.class);
    }
}
